home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / vidhrdw / astrof.c < prev    next >
C/C++ Source or Header  |  2000-04-04  |  6KB  |  264 lines

  1. /***************************************************************************
  2.  
  3.   vidhrdw.c
  4.  
  5.   Functions to emulate the video hardware of Astro Fighter hardware games.
  6.  
  7.   Lee Taylor 28/11/1997
  8.  
  9. ***************************************************************************/
  10.  
  11. #include "driver.h"
  12. #include "vidhrdw/generic.h"
  13.  
  14.  
  15. unsigned char *astrof_color;
  16. unsigned char *tomahawk_protection;
  17.  
  18. static int flipscreen = 0;
  19. static int force_refresh = 0;
  20. static int do_modify_palette = 0;
  21. static int palette_bank = -1, red_on = -1;
  22. static const unsigned char *prom;
  23.  
  24.  
  25. /* Just save the colorprom pointer */
  26. void astrof_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
  27. {
  28.     prom = color_prom;
  29. }
  30.  
  31. /***************************************************************************
  32.  
  33.   Convert the color PROMs into a more useable format.
  34.  
  35.   The palette PROMs are connected to the RGB output this way:
  36.  
  37.   bit 0 -- RED
  38.         -- RED
  39.         -- GREEN
  40.           -- GREEN
  41.         -- BLUE
  42.   bit 5 -- BLUE
  43.  
  44.   I couldn't really determine the resistances, (too many resistors and capacitors)
  45.   so the value below might be off a tad. But since there is also a variable
  46.   resistor for each color gun, this is one of the concievable settings
  47.  
  48. ***************************************************************************/
  49. static void modify_palette(void)
  50. {
  51.     int i, col_index;
  52.  
  53.     col_index = (palette_bank ? 16 : 0);
  54.  
  55.     for (i = 0;i < Machine->drv->total_colors; i++)
  56.     {
  57.         int bit0,bit1,r,g,b;
  58.  
  59.         bit0 = ((prom[col_index] >> 0) & 0x01) | (red_on >> 3);
  60.         bit1 = ((prom[col_index] >> 1) & 0x01) | (red_on >> 3);
  61.         r = 0xc0 * bit0 + 0x3f * bit1;
  62.  
  63.         bit0 = ( prom[col_index] >> 2) & 0x01;
  64.         bit1 = ( prom[col_index] >> 3) & 0x01;
  65.         g = 0xc0 * bit0 + 0x3f * bit1;
  66.  
  67.         bit0 = ( prom[col_index] >> 4) & 0x01;
  68.         bit1 = ( prom[col_index] >> 5) & 0x01;
  69.         b = 0xc0 * bit0 + 0x3f * bit1;
  70.  
  71.         col_index++;
  72.  
  73.         palette_change_color(i,r,g,b);
  74.     }
  75. }
  76.  
  77.  
  78. /***************************************************************************
  79.  
  80.   Start the video hardware emulation.
  81.  
  82. ***************************************************************************/
  83. int astrof_vh_start(void)
  84. {
  85.     if ((colorram = malloc(videoram_size)) == 0)
  86.     {
  87.         generic_bitmapped_vh_stop();
  88.         return 1;
  89.     }
  90.  
  91.     return 0;
  92. }
  93.  
  94.  
  95. /***************************************************************************
  96.  
  97.   Stop the video hardware emulation.
  98.  
  99. ***************************************************************************/
  100. void astrof_vh_stop(void)
  101. {
  102.     if (colorram)  free(colorram);
  103. }
  104.  
  105.  
  106.  
  107. static void common_videoram_w(int offset, int data, int color)
  108. {
  109.     /* DO NOT try to optimize this by comparing if the value actually changed.
  110.        The games write the same data with a different color. For example, the
  111.        fuel meter in Astro Fighter doesn't work with that 'optimization' */
  112.  
  113.     int i,x,y,fore,back;
  114.     int dx = 1;
  115.  
  116.     videoram[offset] = data;
  117.     colorram[offset] = color;
  118.  
  119.     fore = Machine->pens[color | 1];
  120.     back = Machine->pens[color    ];
  121.  
  122.     x = (offset >> 8) << 3;
  123.     y = 255 - (offset & 0xff);
  124.  
  125.     if (flipscreen)
  126.     {
  127.         x = 255 - x;
  128.         y = 255 - y;
  129.         dx = -1;
  130.     }
  131.  
  132.     for (i = 0; i < 8; i++)
  133.     {
  134.         plot_pixel(Machine->scrbitmap, x, y, (data & 1) ? fore : back);
  135.  
  136.         x += dx;
  137.         data >>= 1;
  138.     }
  139. }
  140.  
  141. WRITE_HANDLER( astrof_videoram_w )
  142. {
  143.     // Astro Fighter's palette is set in astrof_video_control2_w, D0 is unused
  144.     common_videoram_w(offset, data, *astrof_color & 0x0e);
  145. }
  146.  
  147. WRITE_HANDLER( tomahawk_videoram_w )
  148. {
  149.     // Tomahawk's palette is set per byte
  150.     common_videoram_w(offset, data, (*astrof_color & 0x0e) | ((*astrof_color & 0x01) << 4));
  151. }
  152.  
  153.  
  154. WRITE_HANDLER( astrof_video_control1_w )
  155. {
  156.     // Video control register 1
  157.     //
  158.     // Bit 0     = Flip screen
  159.     // Bit 1     = Shown in schematics as what appears to be a screen clear
  160.     //             bit, but it's always zero in Astro Fighter
  161.     // Bit 2     = Not hooked up in the schematics, but at one point the game
  162.     //               sets it to 1.
  163.     // Bit 3-7   = Not hooked up
  164.  
  165.     if (input_port_2_r(0) & 0x02) /* Cocktail mode */
  166.     {
  167.         if (flipscreen != (data & 0x01))
  168.         {
  169.             flipscreen = data & 0x01;
  170.             force_refresh = 1;
  171.         }
  172.     }
  173. }
  174.  
  175.  
  176. // Video control register 2
  177. //
  178. // Bit 0     = Hooked up to a connector called OUT0, don't know what it does
  179. // Bit 1     = Hooked up to a connector called OUT1, don't know what it does
  180. // Bit 2     = Palette select in Astro Fighter, unused in Tomahawk
  181. // Bit 3     = Turns on RED color gun regardless of what the value is
  182. //                in the color PROM
  183. // Bit 4-7   = Not hooked up
  184.  
  185. WRITE_HANDLER( astrof_video_control2_w )
  186. {
  187.     if (palette_bank != (data & 0x04))
  188.     {
  189.         palette_bank = (data & 0x04);
  190.         do_modify_palette = 1;
  191.     }
  192.  
  193.     if (red_on != (data & 0x08))
  194.     {
  195.         red_on = data & 0x08;
  196.         do_modify_palette = 1;
  197.     }
  198.  
  199.     /* Defer changing the colors to avoid flicker */
  200. }
  201.  
  202. WRITE_HANDLER( tomahawk_video_control2_w )
  203. {
  204.     if (palette_bank == -1)
  205.     {
  206.         palette_bank = 0;
  207.         do_modify_palette = 1;
  208.     }
  209.  
  210.     if (red_on != (data & 0x08))
  211.     {
  212.         red_on = data & 0x08;
  213.         do_modify_palette = 1;
  214.     }
  215.  
  216.     /* Defer changing the colors to avoid flicker */
  217. }
  218.  
  219.  
  220. READ_HANDLER( tomahawk_protection_r )
  221. {
  222.     /* flip the byte */
  223.  
  224.     int res = ((*tomahawk_protection & 0x01) << 7) |
  225.             ((*tomahawk_protection & 0x02) << 5) |
  226.             ((*tomahawk_protection & 0x04) << 3) |
  227.             ((*tomahawk_protection & 0x08) << 1) |
  228.             ((*tomahawk_protection & 0x10) >> 1) |
  229.             ((*tomahawk_protection & 0x20) >> 3) |
  230.             ((*tomahawk_protection & 0x40) >> 5) |
  231.             ((*tomahawk_protection & 0x80) >> 7);
  232.  
  233.     return res;
  234. }
  235. /***************************************************************************
  236.  
  237.   Draw the game screen in the given osd_bitmap.
  238.   Do NOT call osd_update_display() from this function, it will be called by
  239.   the main emulation engine.
  240.  
  241. ***************************************************************************/
  242. void astrof_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  243. {
  244.     if (do_modify_palette)
  245.     {
  246.         modify_palette();
  247.  
  248.         do_modify_palette = 0;
  249.     }
  250.  
  251.     if (palette_recalc() || full_refresh || force_refresh)
  252.     {
  253.         int offs;
  254.  
  255.         /* redraw bitmap */
  256.         for (offs = 0; offs < videoram_size; offs++)
  257.         {
  258.             common_videoram_w(offs, videoram[offs], colorram[offs]);
  259.         }
  260.     }
  261.  
  262.     force_refresh = 0;
  263. }
  264.